1
|
|
|
define(function(require) { |
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
var OrderTaxesComponent; |
5
|
|
|
var _ = require('underscore'); |
6
|
|
|
var $ = require('jquery'); |
7
|
|
|
var mediator = require('oroui/js/mediator'); |
8
|
|
|
var BaseComponent = require('oroui/js/app/components/base/component'); |
9
|
|
|
var TaxFormatter = require('orotax/js/formatter/tax'); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @export orotax/js/app/components/order-taxes-component |
13
|
|
|
* @extends oroui.app.components.base.Component |
14
|
|
|
* @class orotax.app.components.OrderTaxesComponent |
15
|
|
|
*/ |
16
|
|
|
OrderTaxesComponent = BaseComponent.extend({ |
17
|
|
|
/** |
18
|
|
|
* @property {Object} |
19
|
|
|
*/ |
20
|
|
|
options: { |
21
|
|
|
selectors: { |
22
|
|
|
totalsTemplate: '#order-taxes-totals-template', |
23
|
|
|
collapseSelector: '#order-taxes-totals-table' |
24
|
|
|
} |
25
|
|
|
}, |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @property {Object} |
29
|
|
|
*/ |
30
|
|
|
totalsTemplate: null, |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritDoc |
34
|
|
|
*/ |
35
|
|
|
constructor: function OrderTaxesComponent() { |
36
|
|
|
OrderTaxesComponent.__super__.constructor.apply(this, arguments); |
37
|
|
|
}, |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritDoc |
41
|
|
|
*/ |
42
|
|
|
initialize: function(options) { |
43
|
|
|
this.options = _.defaults(options || {}, this.options); |
44
|
|
|
|
45
|
|
|
mediator.on('entry-point:order:trigger:totals', this.appendTaxResult, this); |
46
|
|
|
|
47
|
|
|
this.totalsTemplate = $(this.options.selectors.totalsTemplate).html(); |
48
|
|
|
}, |
49
|
|
|
|
50
|
|
|
appendTaxResult: function(totals) { |
51
|
|
|
var subtotals = _.extend({subtotals: {}}, totals).subtotals; |
52
|
|
|
_.map(_.where(subtotals, {type: 'tax'}), _.bind(this.prepareItem, this)); |
53
|
|
|
}, |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param {Object} item |
57
|
|
|
*/ |
58
|
|
|
prepareItem: function(item) { |
59
|
|
|
item.data.total = TaxFormatter.formatItem(item.data.total); |
60
|
|
|
item.data.shipping = TaxFormatter.formatItem(item.data.shipping); |
61
|
|
|
item.data.taxes = _.map(item.data.taxes, TaxFormatter.formatTax); |
62
|
|
|
|
63
|
|
|
item.data.in = $(this.options.selectors.collapseSelector).hasClass('in'); |
64
|
|
|
item.template = this.totalsTemplate; |
65
|
|
|
}, |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
dispose: function() { |
71
|
|
|
if (this.disposed) { |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
mediator.off('entry-point:order:trigger:totals', this.appendTaxResult, this); |
76
|
|
|
|
77
|
|
|
OrderTaxesComponent.__super__.dispose.call(this); |
78
|
|
|
} |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
return OrderTaxesComponent; |
82
|
|
|
}); |
83
|
|
|
|